package com.anjubao.parking.municipal.roadside.service;

import com.anjubao.parking.municipal.common.exception.ServiceException;
import com.anjubao.parking.municipal.roadside.dto.UserOweFeeDto;
import com.anjubao.parking.municipal.roadside.mapper.PayRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PayRecordService {
    @Autowired
    private PayRecordMapper payRecordMapper;

    /**
     * 获取用户欠费金额
     * @param userCodeList
     */
    public List<UserOweFeeDto> getUserOweFee(List<String> userCodeList){
        if (userCodeList==null || userCodeList.size()==0){
            throw new ServiceException("用户id不能为空");
        }
        List<UserOweFeeDto> feeDtos=new ArrayList<>();
        userCodeList.stream().forEach(item->{
            UserOweFeeDto feeDto=new UserOweFeeDto();
            Integer oweFee=payRecordMapper.sumOweFee(item);
            feeDto.setUserCode(item);
            feeDto.setOweFee(oweFee==null?0:oweFee);
            feeDtos.add(feeDto);
        });
        return feeDtos;
    }

}
